package software;

import java.util.List;
import java.util.ArrayList;

public class Paination {
    private int currentPage;
    private int totalPages;
    private int pageRows=2;
    private int totalRows;
    private int pageStartRow;
    private int pageEndRow;
    private boolean hasPreviousPage;
    private boolean hasNextPage;
    private List totalList;
    

	
	//分页的一个方法
    public void initPageBean(List totalList){
               this.totalList=totalList;
               this.totalRows=totalList.size();
               this.currentPage=1;
               if(totalRows%pageRows==0){
                totalPages=totalRows/pageRows;
                if(this.totalRows==0){
                 this.pageRows=0;
                }
               }else{
                totalPages=totalRows/pageRows +1;
               }
               this.hasPreviousPage=false;
               if(currentPage==totalPages){
                hasNextPage=false;
               }else{
                hasNextPage=true;
               }
               this.pageStartRow=1;
               if(totalRows<pageRows){
                this.pageEndRow=totalRows;
               }else{
                this.pageEndRow=pageRows;
               }
               
          }

    public void setCurrentPage(int curpage){
    	this.currentPage=curpage;
    	
    }
    //当前页的方法
    public List  getCurrentPageList(){
    	if(currentPage*pageRows<totalRows){//当前页不是最后页
    		pageEndRow=currentPage*pageRows;
    		pageStartRow=pageEndRow-pageRows+1;
    	}else{                             //当前页是最后页
    		pageEndRow=totalRows;
    		pageStartRow=pageRows*(totalPages-1)+1;
    	}
    	List pageList=new ArrayList(pageEndRow-pageStartRow+1);
    	if(totalRows!=0){
    		for(int i=pageStartRow-1;i<pageEndRow;i++){
    			pageList.add(totalList.get(i));
    		}
    	}
    	return pageList;
    	}
		  //上一页的一个方法
		    public List getPreviousPageList(){
		    	currentPage=currentPage-1;
		    	if(currentPage<1){
		    		currentPage=1;
		    	}
		    	if(currentPage>=totalPages){
		    		hasNextPage=false;
		    	}else{
		    		hasNextPage=true;
		    	}
		    	if((currentPage-1)>0){
		    		hasPreviousPage=true;
		    	}else{
		    		hasPreviousPage=false;
		    	}
		    	List pageList=this.getCurrentPageList();
		    	return pageList;
		    }
		  //下一页的一个方法
		    public List getNextPageList(){
		     currentPage=currentPage+1;
		     if(currentPage>totalPages){
		      currentPage=totalPages;
		     }
		     if((currentPage-1)>0){
		      hasPreviousPage=true;
		     }else{
		      hasPreviousPage=false;
		     }
		     if(currentPage>=totalPages){
		      hasNextPage=false;
		     }else{
		      hasNextPage=true;
		     }
		     List pageList=this.getCurrentPageList();
		     return pageList;
		    }
	    //页
	    public List AppointPageList(int jumpPage){
	        this.currentPage=jumpPage;
	        if(currentPage>this.totalPages){
	         this.currentPage=this.totalPages;
	        }
	        if(currentPage<1){
	        this.currentPage=1;
	        }
	        if(currentPage>1){
	       this.hasPreviousPage=true;
	        }else{
	         this.hasPreviousPage=false;
	        }
	        if(this.currentPage<this.totalPages){
	         this.hasNextPage=true;
	        }else{
	         this.hasNextPage=false;
	        }
	        List pageList=this.getCurrentPageList();
	        return pageList;
	       }
	    
	       public int getCurrentPage() {
		     return currentPage;
		    }
	       
		    public boolean isHasNextPage() {
		     return hasNextPage;
		    }
		    
		    public boolean isHasPreviousPage() {
		     return hasPreviousPage;
		    }
		    
		    public int getPageEndRow() {
		     return pageEndRow;
		    }
		    
		    public int getPageRows() {
		     return pageRows=1;
		    }
		    
		    public int getPageStartRow() {
		     return pageStartRow;
		    }
		    
		    public List getTotalList() {
		     return totalList;
		    }
		    
		    public int getTotalPages() {
		     return totalPages;
		    }
		    
		    public int getTotalRows() {
		     return totalRows;
		    }
		    
		    /*public void setTotalPages(int totalPages) {
				this.totalPages = totalPages;
		    }*/

}
